package miaofusdk

import (
	"encoding/json"
)

// func ConvertPayChannel(in string) string {
// 	out := ""

// 	if in == "微信" || strings.ToLower(in) == "wechat" {
// 		return "wechat"
// 	} else if in == "支付宝" || strings.ToLower(in) == "alipay" {
// 		return "alipay"
// 	}

// 	return out
// }

type NewOrderStats struct {
	Amount       int    `json:"amount"`                //商户实收总金额
	Count        int    `json:"count"`                 //总交易笔数
	Fee          int    `json:"fee"`                   //商户手续费总金额
	RefundAmount int    `json:"refund_amount"`         //退款总金额
	RefundCount  int    `json:"refund_count"`          //总退款笔数
	PayChannel   string `json:"pay_channel,omitempty"` //交易渠道...
	Day          string `json:"day,omitempty"`         //交易日期
}

type RespNewOrderStats struct {
	Response
	Data map[string]NewOrderStats `json:"data"` //分渠道统计列表
}

type RespNewOrderStatsGroup struct {
	Response
	Data map[string]map[string]NewOrderStats `json:"data"` //日期的统计
}

///新对账单的接口
func (s *SrvDataCenterManager) NewOrderStats(trade_status, pay_channel, start_time, end_time, store_code, shop_code, org_code string) (RespNewOrderStats, error) {
	resp := RespNewOrderStats{}
	http_request := s.GetPost(s.GetUrl() + "/order/stats")
	http_request.Param("trade_status", trade_status)
	http_request.Param("pay_channel", pay_channel)
	http_request.Param("start_time", start_time)
	http_request.Param("end_time", end_time)
	http_request.Param("start_time", start_time)
	http_request.Param("store_code", store_code)
	http_request.Param("shop_code", shop_code)
	http_request.Param("org_code", org_code)
	if v, err := http_request.Bytes(); err != nil {
		return resp, err
	} else if err := json.Unmarshal(v, &resp); err != nil {
		return resp, err
	} else {
		return resp, nil
	}
}

type FileUploadBean struct {
	Response
	MD5 string `json:"md5"`
	URL string `json:"url"`
}

type NewOrderBean struct {
	Id                 int    `json:"id"`
	PayChannel         string `json:"pay_channel"`
	TradeNo            string `json:"trade_no"`
	UpTradeNo          string `json:"up_trade_no"`
	ChannelTradeNo     string `json:"channel_trade_no"`
	CreateTime         string `json:"create_time"`
	PayTime            string `json:"pay_time"`
	BuyerUserId        string `json:"buyer_user_id"`
	BuyerUserName      string `json:"buyer_user_name"`
	PayAmount          int    `json:"pay_amount"`
	ReceiptAmount      int    `json:"receipt_amount"`
	BuyerAmount        int    `json:"buyer_amount"`
	Fee                int    `json:"fee"`
	FeeLv              string `json:"fee_lv"`
	SettleAmount       int    `json:"settle_amount"`
	Income             int    `json:"income"`
	Outcome            int    `json:"outcome"`
	PayScene           string `json:"pay_scene"`
	RefundTime         string `json:"refund_time"`
	RefundUpTradeNo    string `json:"refund_up_trade_no"`
	TerminalCode       string `json:"terminal_code"`
	OperatorCode       string `json:"operator_code"`
	RefundTerminalCode string `json:"refund_terminal_code"`
	RefundOperatorCode string `json:"refund_operator_code"`
	StoreCode          string `json:"store_code"`
	ShopCode           string `json:"shop_code"`
	OrgCode            string `json:"org_code"`
	StoreName          string `json:"store_name"`
	LocalExsit         string `json:"local_exsit"`
	ChnType            string `json:"chn_type"`
	DccFlag            string `json:"dcc_flag"`
}

type RespNewOrder struct {
	Response
	Page       int            `json:"page,string"`
	Rows       int            `json:"rows,string"`
	TotalCount int            `json:"total_count,string"`
	TotalPage  int            `json:"total_page,string"`
	List       []NewOrderBean `json:"list,omitempty,string"`
}
